<style>
    .layui-btn:not(.layui-btn-lg ):not(.layui-btn-sm):not(.layui-btn-xs) {height:34px;line-height:34px;padding:0 8px;}
</style>
<body>
<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
        <div >
            <table id="table" class="layui-table" lay-filter="table"></table>
        </div>
    </div>
</div>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <a class="layui-btn layui-btn-normal layui-btn-sm" href="javascript:;" layuimini-href="news/create">添加</a>
    </div>
</script>
<!-- 状态列 -->
<script type="text/html" id="is_show">
    <input type="checkbox" name="is_show" value="@{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="is_show" @{{ d.is_show == 1 ? 'checked' : '' }}>
</script>

<!-- 状态列 -->
<script type="text/html" id="recommend">
    <input type="checkbox" name="recommend" value="@{{d.id}}" title="推荐" lay-filter="recommend" @{{ d.recommend == 1 ? 'checked' : '' }}>
</script>
<!-- 操作列 -->
<script type="text/html" id="auth-state">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    layui.use(['table','miniIndex'], function () {
        var $ = layui.jquery;
        var table = layui.table;
        var miniIndex = layui.miniIndex;

        // 渲染表格
        layer.load(2);
        var table_list = table.render({
            elem: '#table',
            url: 'news/list',
            toolbar: '#toolbarDemo',
            title: '模型数据表',
            page: true,
            limit: 10,
            cols: [[
                {type: 'numbers'},
                {field: 'news_title', title: '新闻标题'},
                {field: 'title', title: 'SEO Title'},
                {templet: '#is_show', title: '显示'},
                {templet: '#recommend', title: '推荐'},
                {field: 'created_at', title: '添加时间'},
                {field: 'updated_at', title: '更新时间'},
                {templet: '#auth-state', width: 120, align: 'center', title: '操作'}
            ]],
            done: function () {
                layer.closeAll('loading');
            }
        });
        // 表格操作事件
        miniIndex.tableEvent('news');

        // 表格表单事件
        // 切换推荐状态
        miniIndex.tableCheckbox(table_list, 'news' , 'recommend');
        // 切换显示状态
        miniIndex.tableSwitch(table_list, 'news' , 'is_show')
    });
</script>
</body>
